# /**
# * Copyright (c) 2022 Beijing Jiaotong University
# * PhotLab is licensed under [Open Source License].
# * You can use this software according to the terms and conditions of the [Open Source License].
# *
# * You may obtain a copy of [Open Source License] at: [https://open.source.license/]
# *
# * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# *
# * See the [Open Source License] for more details.
# */
# /**
# * Author: Shihao Xie
# * Created: Apr. 17, 2023
# * Supported by: National Key Research and Development Program of China
# */

import time

from phot_server.rpc.graph_data_type.ttypes import PhotGraph, RenderGraph, PhotParameter


class GraphFactory:
    def __init__(self):
        pass

    def get_new_phot_graph(self, graph_name) -> PhotGraph:
        """
        This method is to new an empty graph to graph container
        :return: PhotGraph object that contain graph data
        """
        graph = PhotGraph()
        graph.graphId = self.create_graph_id(graph_name)
        graph.name = graph_name
        graph.createTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
        graph.version = "1.0.0.1"
        graph.author = ""
        graph.description = ""
        graph.graphParameters = {"systemGlobalSimulationParameter": [
            PhotParameter(name="num_symbols", dataType="int", value="65536", unit="", photUnit="",
                          nameTag="number of symbols", category="systemGlobalSimulationParameter"),
            PhotParameter(name="bits_per_symbol", dataType="int", value="4", unit="", photUnit="",
                          nameTag="number of bits per symbol", category="systemGlobalSimulationParameter"),
            PhotParameter(name="total_baud", dataType="float", value="60e9", unit="", photUnit="", nameTag="total baud",
                          category="systemGlobalSimulationParameter"),
            PhotParameter(name="up_sampling_factor", dataType="int", value="2", unit="", photUnit="",
                          nameTag="up sampling factor", category="systemGlobalSimulationParameter"),
            PhotParameter(name="sampling_rate", dataType="float", value="120e9", unit="",
                          photUnit="", nameTag="sampling rate", category="systemGlobalSimulationParameter"),
            PhotParameter(name="Reference_frequency", dataType="float", value="193.1e12", unit="", photUnit="",
                          nameTag="reference frequency", category="systemGlobalSimulationParameter"),
        ]}

        graph.components = []
        graph.links = []
        return graph

    def get_new_render_graph(self, graph_id) -> RenderGraph:
        """
        This method is to new an empty render graph to graph container
        :return: PhotRenderGraph object that contain graph render data
        """
        return RenderGraph(graphId=graph_id, nodes=[], routes=[], texts=[])

    def create_graph_id(self, graph_name=None):
        time_string = time.strftime("%Y-%m-%d_%H:%M:%S", time.localtime(time.time()))
        if graph_name is not None:
            return "{}_{}".format(graph_name, time_string)
        else:
            return "graph_{}".format(graph_name, time_string)
